package com.xinfu.newproject.presenter;

import com.xinfu.newproject.bean.matter_repair.RepairDetailBean;
import com.xinfu.newproject.bean.matter_repair.RepairDetailBody;
import com.xinfu.newproject.bean.matter_repair.RepairRecordBean;
import com.xinfu.newproject.bean.matter_repair.RepairRecordBody;
import com.xinfu.newproject.bean.matter_repair.bean.RepairCountBean;
import com.xinfu.newproject.bean.matter_repair.body.RepairCountBody;
import com.xinfu.newproject.callback.MyCallBack;
import com.xinfu.newproject.model.matter_repair.RepairRecordModel;
import com.xinfu.newproject.view.IView;

import io.reactivex.disposables.Disposable;

public class RepairRecordPresenter {
    private IView.IRepairRecordView mIRepairRecordView;

    private RepairRecordModel mRepairRecordModel;

    public RepairRecordPresenter(IView.IRepairRecordView iRepairRecordView) {
        this.mIRepairRecordView = iRepairRecordView;
        mRepairRecordModel = new RepairRecordModel();
    }

    /**
     * 查询报事报修
     */
    public void repairRecord() {

        RepairRecordBody repairRecordBody = new RepairRecordBody(mIRepairRecordView.header(),
                mIRepairRecordView.userId());

        mRepairRecordModel.repairRecord(repairRecordBody, new MyCallBack<RepairRecordBean>() {
            @Override
            public void onSuccess(RepairRecordBean repairRecordBean) {

                if (repairRecordBean.isSuccess()) {
                    mIRepairRecordView.getData(repairRecordBean);
                } else {
                    mIRepairRecordView.showToast(repairRecordBean.getMessage());
                }
//                mIRepairRecordView.showToast(repairRecordBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {

                mIRepairRecordView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIRepairRecordView.closeDispose(disposable);
            }
        });


    }

    /**
     * 查询报事报修详情
     */
    public void repairDetail() {

        RepairDetailBody repairDetailBody = new RepairDetailBody(mIRepairRecordView.header(),
                mIRepairRecordView.repairId());

        mRepairRecordModel.repairDetail(repairDetailBody, new MyCallBack<RepairDetailBean>() {
            @Override
            public void onSuccess(RepairDetailBean repairDetailBean) {

                if (repairDetailBean.isSuccess()) {
                    mIRepairRecordView.getData(repairDetailBean);
                } else {
                    mIRepairRecordView.showToast(repairDetailBean.getMessage());
                }
//                mIRepairRecordView.showToast(repairDetailBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {

                mIRepairRecordView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIRepairRecordView.closeDispose(disposable);
            }
        });


    }

    /**
     * 查询报修数量
     */
    public void repairCount() {

        RepairCountBody repairCountBody = new RepairCountBody(mIRepairRecordView.header(),
                mIRepairRecordView.userId());

        mRepairRecordModel.repairCount(repairCountBody, new MyCallBack<RepairCountBean>() {
            @Override
            public void onSuccess(RepairCountBean repairCountBean) {
                if (repairCountBean.isSuccess()) {
                    mIRepairRecordView.getData(repairCountBean);
                } else {
                    mIRepairRecordView.showToast(repairCountBean.getMessage());
                }
//                mIRepairRecordView.showToast(repairDetailBean.getMessage());
            }

            @Override
            public void onError(String header, String message) {
                mIRepairRecordView.showToast(message);
            }

            @Override
            public void onDispose(Disposable disposable) {
                mIRepairRecordView.closeDispose(disposable);
            }
        });


    }

}
